package com.qingcheng.controller;

import com.qingcheng.entity.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

//控制器通知类
@ControllerAdvice
public class BaseExceptionHandler {

    @ExceptionHandler(Exception.class)
//    当出现一常时，走这
    @ResponseBody
//    放回的结果变json
    public Result error(Exception e)
    {
        e.printStackTrace();
        System.out.println("调用异常处理");
        return new Result(1,e.getMessage());
    }
}
